package com.zhc.dejingapi.service.upload.impl;

import com.zhc.dejingapi.pojo.param.QingCommonBackResult;
import com.zhc.dejingapi.pojo.qingflow.QingflowApiInfo;
import com.zhc.dejingapi.service.upload.IQingXiReportDataGetService;
import com.zhc.dejingapi.utils.HttpClientUtil;
import com.zhc.dejingapi.utils.qingxi.QingXiTokenUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
public class QingXiReportDataGetServiceImpl implements IQingXiReportDataGetService {
    @Autowired
    QingflowApiInfo qqingflowApiInfo;


    private final RedisTemplate<String,Object> redisTemplate;


    private final JdbcTemplate mySqlJdbcTemplate;

    public QingXiReportDataGetServiceImpl(@Qualifier("mySqlJdbcTemplate")JdbcTemplate mySqlJdbcTemplate1,
                                          @Qualifier("redisTemplateWin")RedisTemplate<String, Object> redisTemplate1) {
        this.redisTemplate = redisTemplate1;
        this.mySqlJdbcTemplate = mySqlJdbcTemplate1;

    }

    @Override
    public QingCommonBackResult GetTableReportData(String strChartKey) {
        QingCommonBackResult commonBackResult = new QingCommonBackResult();
        try{
            String strToken= QingXiTokenUtils.GetUserToken(qqingflowApiInfo);
            String strUrl= qqingflowApiInfo.getServerUrl();
            if(!strUrl.endsWith("/")){
                strUrl=strUrl+"/";
            }
            strUrl+="qingbi/charts/data/"+strChartKey;
            Map<String,String> mapHeaderPara=new HashMap<>();
            mapHeaderPara.put("Token",strToken);
            mapHeaderPara.put("Wsid",QingXiTokenUtils._QingxiWSId+"");

            String strBackData= HttpClientUtil.doGet(strUrl,mapHeaderPara);
            if(strBackData==null||strBackData.equals("")){
                throw new Exception("返回数据为空");
            }
            else{



            }

        }
        catch (Exception e){
            e.printStackTrace();
            commonBackResult.setErrCode(-10012);
            commonBackResult.setErrMsg("出错："+e.getMessage()+"\n"+e.getStackTrace());
        }
        return commonBackResult;
    }

    @Override
    public QingCommonBackResult GetKPIReportData(String strChartKey) {
        return null;
    }
}
